<template>
	<view>
		<view v-if="!addStr" class="addr-select">
			<view class="content">
				<button @click="showAddress" size="mini" type="primary">请选择收货地址+</button>
			</view>
		</view>
		<view v-else @click="showAddress" class="addr-info">
			<view class="user-info">
				<view>收货人：{{ address.userName }}</view>
				<view>
					<text>电话： {{ address.telNumber }}</text>
					<uni-icons type="forward"/>
				</view>
			</view>
			<view>收货地址：{{ addStr }}</view>
		</view>
		<!-- 图片 -->
		<view>
			<image src="/static/cart_border@2x.png" />
		</view>
	</view>
</template>

<script>
import { mapState, mapGetters } from 'vuex'
export default {
	name: 'my-address',
	computed: {
		...mapState('m_user', ['address']),
		...mapGetters('m_user', ['addStr'])
	},
	data() {
		return {}
	},
	methods: {
		async showAddress() {
			const res = await uni.chooseAddress()
			if (res[0]) {
				uni.$showToast('没有选择任何地址')
			} else {
				this.$store.commit('m_user/setAddress', res)
			}
		}
	}
}
</script>

<style lang="scss">
.addr-select {
		display: flex;
		justify-content: center;
		align-items: center;
		height: 180rpx;
	.content {
	}
}
.addr-info {
	height: 180rpx;
	display: flex;
	flex-direction: column;
	justify-content: center;
	padding: 0 20rpx;
	.user-info {
		display: flex;
		justify-content: space-between;
		margin-bottom: 10px;
		text {
			margin-right: 10rpx;
		}
	}
}
image {
	width: 100%;
	height: 5px;
}
</style>